package com.servlet.model.base;

import java.io.Serializable;
import java.sql.Date;

/**
 * Etude dans la base de donnée
 * Chaque utilisateur peut avoir plusieurs études
 * @author Jing Jing
 */
public class Study  implements Serializable {
	private String email;
	private String school;
	private Date date_begin;
	private Date date_end;
	/**
	 * Spécialité
	 */
	private String major;
	private Area area;

	private boolean is_modified_school;
	private boolean is_modified_date_begin;
	private boolean is_modified_date_end;
	private boolean is_modified_major;
	private boolean is_modified_area;

	public Study() {
		email = null;
		school = null;
		date_begin = null;
		date_end = null;
		major = null;
		area = null;
		is_modified_school = false;
		is_modified_date_begin = false;
		is_modified_date_end = false;
		is_modified_major = false;
		is_modified_area = false;
	}

	public Study(String email, String school, Date date_begin, Date date_end,
			String major, Area area) {
		this.email = email;
		this.school = school;
		this.date_begin = date_begin;
		this.date_end = date_end;
		this.major = major;
		this.area = area;
		is_modified_school = false;
		is_modified_date_begin = false;
		is_modified_date_end = false;
		is_modified_major = false;
		is_modified_area = false;
	}

	public String getEmail() {
		return email;
	}

	public String getSchool() {
		return school;
	}

	public Date getDateBegin() {
		return date_begin;
	}

	public Date getDateEnd() {
		return date_end;
	}

	public String getMajor() {
		return major;
	}

	public Area getArea() {
		return area;
	}

	public boolean getIs_modified_school() {
		return is_modified_school;
	}

	public boolean getIs_modified_area() {
		return is_modified_area;
	}

	public boolean getIs_modified_major() {
		return is_modified_major;
	}

	public boolean getIs_modified_date_begin() {
		return is_modified_date_begin;
	}

	public boolean getIs_modified_date_end() {
		return is_modified_date_end;
	}

	public void setIs_modified_school(boolean is_modified_school) {
		this.is_modified_school = is_modified_school;
	}

	public void setIs_modified_area(boolean is_modified_area) {
		this.is_modified_area = is_modified_area;
	}

	public void setIs_modified_major(boolean is_modified_major) {
		this.is_modified_major = is_modified_major;
	}

	public void setIs_modified_date_begin(boolean is_modified_date_begin) {
		this.is_modified_date_begin = is_modified_date_begin;
	}

	public void setIs_modified_date_end(boolean is_modified_date_end) {
		this.is_modified_date_end = is_modified_date_end;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}
	
	public void setSchool(String school) {
		this.school = school;
		is_modified_school = true;
	}

	public void setDateBegin(Date date_begin) {
		this.date_begin = date_begin;
		is_modified_date_begin = true;
	}

	public void setDateEnd(Date date_end) {
		this.date_end = date_end;
		is_modified_date_end = true;
	}

	public void setMajor(String major) {
		this.major = major;
		is_modified_major = true;
	}

	public void setArea(Area area) {
		this.area = area;
		is_modified_area = true;
	}

	public String generateInsertSQL() {
		String insertSQL = "INSERT INTO study VALUES ('" + email + "' ,'"
				+ school + "' ,'" + date_begin + "' ,'" + date_end + "'";

		if (major != null)
			insertSQL += " ,'" + major + "'";
		else
			insertSQL += " , null";

		if (area != null)
			insertSQL += " ," + area.getHCode();
		else
			insertSQL += " , null";

		insertSQL += ")";

		return insertSQL;
	}

	public String generateDeleteSQL() {
		String deleteSQL = "DELETE FROM study WHERE email='" + email
				+ "' AND school='" + school + "' AND date_begin='" + date_begin
				+ "'";
		return deleteSQL;
	}
}
